<template>
  <div id="person-message">
    <h3>个人信息</h3>
    <div v-for="(item, index) in messagelist" :key="index">
      <div class="form">
        <group>
          <cell :title="'姓名'" :value="item.userName" is-link @click.native="changeName"></cell>
          <cell :title="'手机'" :value="item.mobile" is-link @click.native="changeMobile"></cell>
          <cell :title="'所在城市'" :value="item.province + ' ' + item.city" ></cell>
        </group>
      </div>
      <h3>账号设置</h3>
      <group>
        <cell :title="'提现卡'" :value="item.bankName + bankcard" is-link @click.native="changeCredit"></cell>
      </group>
      <!-- <p class="p-warn">提现卡修改时间为每月20-30日，其他时间不可修改。</p> -->
    </div>
    <div class="logout"><span @click="logoff">退出登录</span></div>
  </div>
</template>
<script>
var timeStamp = String(Number(new Date()))
import { Cell, Group } from 'vux'
import api from '../../api'
import utils from '../../utils'
export default {
  data () {
    return {
      messagelist: [],
      tokenval: '',
      bankcard: '',
      nowMobile: ''
    }
  },
  components: {
    Cell,
    Group
  },
  created () {
    window.document.title = '个人信息'
    this.tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
    var params = {
      Tokenuser: this.tokenval,
      userid: this.$store.state.userID,
      timestamp: timeStamp
    }
    api.message(params).then(res => {
      console.log(JSON.stringify(res))
      this.messagelist = this.messagelist.concat(res.data)
      this.nowMobile = res.data.mobile
      var creditcode = res.data.bankCard
      if (creditcode === '') {
        this.bankcard = ''
      } else {
        this.bankcard = '(' + creditcode.substring(creditcode.length - 4) + ')'
      }
    })
    utils.jssdkwx(api, this.$wechat, this.$store)
  },
  methods: {
    logoff () { // 退出登录
      api.logout({
        token: this.tokenval,
        timestamp: timeStamp,
        userId: this.$store.state.userID
      }).then(res => {
        if (res.status === 200) {
          localStorage.removeItem('authorized')
          localStorage.removeItem('userk')
          localStorage.removeItem('userid')
          this.$router.push('/passport/login')
          utils.redirectWx('-3')
        } else {
          this.$vux.toast.show({
            text: res.message,
            type: 'warn',
            width: '4rem'
          })
        }
      })
    },
    changeName () {
      this.$router.push('/setting/name')
    },
    changeMobile () {
      this.$router.push('/setting/mobile?mobile=' + this.nowMobile)
    },
    changeCredit () {
      window.location.href = '/setting/card'
      // var day = new Date().getDate()
      // if (day < 20) {
      //   this.$vux.toast.show({
      //     text: '请在20号以后修改提现卡',
      //     type: 'warn',
      //     width: '4rem'
      //   })
      // } else {
      // }
    }
  }
}
</script>
